package com.gitee.ly.openfeign;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cloud.openfeign.FeignContext;

public class OpenFeignBeanPostProcessor implements BeanPostProcessor {
    private BeanFactory beanFactory;

    public OpenFeignBeanPostProcessor(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof FeignContext && !(bean instanceof LightRegistryFeignContext)) {
            return new LightRegistryFeignContext(this.beanFactory, (FeignContext) bean);
        }
        return bean;
    }
}
